#include "precomp.h"
#include "GoalThink.h"
#include "GoalMoveToPos.h"
#include "GoalFollowPath.h"
#include "../Entity.h"
#include "../../Map/Pathfinding.h"

namespace Tmpl {

GoalThink::GoalThink(Entity* owner) : GoalComposite(owner)
{
}

void GoalThink::Activate()
{
	mStatus = Goal::GOALSTATUS_ACTIVE;
}

void GoalThink::Process(char threadId)
{
	//mOwner->AddFlag(0);
	mStatus = ProcessSubGoals(threadId);
	if (mStatus == GOALSTATUS_NO_SUB_GOALS)
	{
		/*
		GoalFollowPath* followPath = new GoalFollowPath(mOwner);
		followPath->AddPathPoint(Vec2f(RandF(10), RandF(10)));
		followPath->AddPathPoint(Vec2f(RandF(10), RandF(10)));
		followPath->AddPathPoint(Vec2f(RandF(10), RandF(10)));
		followPath->SetLooping(true);
		*/

		GoalFollowPath* followPath = Navigator::NavigateTo(mOwner, mOwner->GetPos(), Vec2f(RandF(32), RandF(32)), threadId+1);
		if (followPath) AddSubgoal(followPath);

		//AddSubgoal(new GoalMoveToPos(mOwner, Vec2f(RandF(10), RandF(10))));

		mStatus = Goal::GOALSTATUS_ACTIVE;
	}
}
void GoalThink::Terminate()
{
}

bool GoalThink::HandleMessage(const MsgData& msg)
{ 
	return ForwardMessageToFrontMostSubgoal(msg); 
}

}
